#ifndef CELL_H
#define CELL_H

#include <vector>
#include <boost/smart_ptr.hpp>

#include "Object.h"

class Cell;

  // pathfinding functions, used in Controller.cpp
int manhattanDistance( int x1, int y1, int x2, int y2 );
bool isPassable( Object* o );
int movementCost( Cell c );
int calcF( int x2, int y2, Cell c );
bool isInList( int x, int y, vector<Cell>& list );
Cell getFromList( int x, int y, vector<Cell>& list );
  // checks, if pointer is null
bool isNull( void* );

  // is used in pathfinding algorithm, gonna make space-time A* later
  // ( time is for space-time A* )
class Cell
{
    public:
        Cell( int x_, int y_, int t, boost::shared_ptr<Cell> c, int x2, int y2 )
            :x(x_), y(y_), time(t), path( c ),
             g( movementCost(*this) ), f( calcF( x2, y2, *this ) )
        {}
        Cell( int x_, int y_, int t, int x2, int y2 )
            :x(x_), y(y_), time(t), g( movementCost(*this) ),
            f( calcF( x2, y2, *this ) )
        {}
        int getX() const { return x; }
        int getY() const { return y; }
        int getTime() const { return time; }
        int getG() const { return g; }
        int getF() const { return f; }
        boost::shared_ptr<Cell> getPath() const { return path; }

        void setPath( boost::shared_ptr<Cell> i ) { path = i; }

        bool operator >  ( Cell& );
        bool operator <  ( Cell& );
        bool operator == ( Cell& );
        bool operator >= ( Cell& );
        bool operator <= ( Cell& );

          // returns false if it is null
        bool isNull();

        ~Cell() {}
    private:
          // coordinates of a cell
        int x, y, time;
          // a cell from which we move to this one
        boost::shared_ptr<Cell> path;
          // cost of moving to that cell
        int g;
          // priority of choosing this cell for going to it
        int f;
};

#endif // CELL_H
